# -*- coding: utf-8 -*-
"""
Created on Tue May 14 17:24:38 2024

@author: 29865
"""

import pandas as pd
import matplotlib.pyplot as plt
path = '一、车次上车人数统计表.xlsx'
data = pd.read_excel(path)
D=data.iloc[:,0]
D=list(D.unique())  #车次号D02~D06

list1=[]    #预定义每个车次的上车人数列表
for d in D:
    dt=data.loc[data['车次'] == d,['上车人数']]
    s=dt.sum()
    list1.append(s['上车人数']) #或者s[0]

# 2.绘制饼图
plt.pie(list1,labels=D,autopct='%1.2f%%') #绘制饼图，百分比保留小数点后两位
plt.title('各车次上车人数百分比饼图')